import QtQuick
import QtQuick.Controls
import QtQuick.Effects
import QtQuick.Layouts

Item {
    id: root

    Theme { id: theme }
    FontLoader {
        id: iconFont
        source: "qrc:/assets/fontawesome-free-6.7.2-desktop/otfs/Font Awesome 6 Free-Solid-900.otf"
    }
    // 所有的预设值
    // 设置数据状态
    property string currentTab: "system" // "system" 或 "login"

    // 选配设置状态
    property bool phEnabled: true
    property bool conductivityEnabled: false
    property bool temperatureEnabled: false

    // 语言设置
    property string language: "chinese" // "chinese" 或 "english"

    // 数据采样时间
    property string dataSamplingPeriod: "10s" // "10s","20s","30s","1min","2min","5min","10min","30min"

    // 单位设置
    property string weightUnit: "g" // "g" 或 "kg"
    property string decimalPlaces: "1" // "1","2","3"
    property string temperatureUnit: "celsius" // "celsius" 或 "fahrenheit"

    // 日期时间格式
    property string dateFormat: "yyyy_mm_dd" // "yyyy_mm_dd", "mm_dd_yyyy", "dd_mm_yyyy"
    property string timeFormat: "hh_mm_ss" // "hh_mm_ss" 或 "hh_mm"

    // 时钟设置
    property string clockType: "local" // "local" 或 "network"

    // 电子签名设置
    property string signatureType: "one" // "one", "two", "none"

    // 网络通讯设置
    property string networkType: "wired" // "wired" 或 "wireless"

    // 登录设置状态
    property string passwordComplexity: "simple" // "simple" 或 "complex"
    property int passwordLength: 6 // 6, 8, 10, 12
    property string passwordLockAttempts: "5" // "3", "5", "10", "none"
    property string lockDuration: "3min" // "3min", "5min", "10min", "30min", "24h", "none"
    property string autoLogoutWait: "5min" // "5min", "10min", "30min", "60min", "none"

    Component.onCompleted: {
        console.log("组件加载完成，开始初始化数据");
        loadData();
    }

    function loadData() {
        var data = settingInfo.getSettingParams();

        if (data.system_optional && data.system_optional.includes("ph")) phEnabled=true;
        else phEnabled = false;

        if (data.system_optional && data.system_optional.includes("conductivity")) conductivityEnabled=true;
        else  conductivityEnabled = false;

        if (data.system_optional && data.system_optional.includes("temperature")) temperatureEnabled=true;
        else temperatureEnabled=false;

        language            = data.system_language;
        dataSamplingPeriod  = data.system_dataSamplingPeriod;
        weightUnit          = data.system_weightUnit
        decimalPlaces       = data.system_decimalPlaces;
        temperatureUnit     = data.system_temperatureUnit
        dateFormat          = data.system_dateFormat
        timeFormat          = data.system_timeFormat

        clockType           = data.system_clockType
        signatureType       = data.system_signatureType
        networkType         = data.system_networkType

        passwordComplexity  =   data.login_passwordComplexity
        passwordLength      =   data.login_passwordLength
        passwordLockAttempts=  data.login_passwordLockAttempts
        lockDuration        =   data.login_lockDuration
        autoLogoutWait      =   data.login_autoLogoutWait
    }

    function saveSystemOptional(){
        var optional=""
        if (phEnabled) optional+= "ph_"
        if (conductivityEnabled) optional+= "conductivity_"
        if (temperatureEnabled) optional+= "temperature_"
        settingInfo.saveSettingParam("system_optional", optional);
    }

    Rectangle {
        color: "transparent"
    }

    // 顶部标签页切换
    Item {
        id: tabHeader
        anchors.top: parent.top
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.topMargin: 10
        width: 1260 // 500 + 60 + 500
        height: 100

            Row {
                id: tabRow
                anchors.centerIn: parent
                spacing: 100

            // 系统设置标签
            Rectangle {
                id: systemTab
                width: 500
                height: 100
                radius: 30
                color: "transparent"
                z: currentTab === "system" ? 2 : 1

                Image {
                    anchors.fill: parent
                    source: currentTab === "system" ? "qrc:/assets/buttoninner.png" : "qrc:/assets/buttonout.png"
                    fillMode: Image.Stretch
                }

                Text {
                    anchors.centerIn: parent
                    anchors.verticalCenterOffset: 4
                    text: "系统设置"
                    font.pixelSize: 24
                    color: currentTab === "system" ? theme.focusColor : "#7A8CA5"
                    font.bold: true
                }

                MouseArea {
                    anchors.fill: parent
                    cursorShape: Qt.PointingHandCursor
                    onClicked: currentTab = "system"
                }
            }

            // 登录设置标签
            Rectangle {
                id: loginTab
                width: 500
                height: 100
                radius: 30
                color: "transparent"
                z: currentTab === "login" ? 2 : 1

                Image {
                    anchors.fill: parent
                    source: currentTab === "login" ? "qrc:/assets/buttoninner.png" : "qrc:/assets/buttonout.png"
                    fillMode: Image.Stretch
                }

                Text {
                    anchors.centerIn: parent
                    anchors.verticalCenterOffset: 4
                    text: "登录设置"
                    font.pixelSize: 24
                    color: currentTab === "login" ? theme.focusColor : "#7A8CA5"
                    font.bold: true
                }

                MouseArea {
                    anchors.fill: parent
                    cursorShape: Qt.PointingHandCursor
                    onClicked: currentTab = "login"
                }
            }
        }
    }

    // 设置内容区域
    Flickable {
        id: scrollFlick
        anchors.top: tabHeader.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.topMargin: 15
        anchors.leftMargin: - 10
        anchors.rightMargin: - 10
        anchors.bottomMargin: 20

        clip: true
        interactive: true
        boundsBehavior: Flickable.DragOverBounds
        pressDelay: 120

        // 禁用水平拖动
        flickableDirection: Flickable.VerticalFlick

        contentWidth: width - 40
        contentHeight: currentTab === "system" ? contentCol.height : loginCol.height

        ScrollBar.vertical: ScrollBar {
            policy: ScrollBar.AsNeeded
            visible: scrollFlick.contentHeight > scrollFlick.height && (scrollFlick.moving || scrollFlick.flicking || scrollFlick.dragging)
        }

        Column {
            id: contentCol
            width: scrollFlick.width - 40
            spacing: 24
            anchors.horizontalCenter: parent.horizontalCenter
            visible: currentTab === "system"

            // 选配设置
            SettingSection {
                title: "选配设置："
                content: RowLayout {
                    spacing: 100

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "pH"
                        checked: phEnabled
                        onClicked: {
                            phEnabled = !phEnabled
                            console.log("选配设置-pH：" + (phEnabled ? "启用" : "禁用"))
                            saveSystemOptional()
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "电导"
                        checked: conductivityEnabled
                        onClicked: {
                            conductivityEnabled = !conductivityEnabled
                            console.log("选配设置-电导：" + (conductivityEnabled ? "启用" : "禁用"))
                            saveSystemOptional()
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "温度"
                        checked: temperatureEnabled
                        onClicked: {
                            temperatureEnabled = !temperatureEnabled
                            console.log("选配设置-温度：" + (temperatureEnabled ? "启用" : "禁用"))
                            saveSystemOptional()
                        }
                    }
                }
            }

            // 语言设置
            SettingSection {
                title: "语言设置："
                content: RowLayout {
                    spacing: 100

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "中文"
                        checked: language === "chinese"
                        onClicked: {
                            language = "chinese"
                            console.log("语言设置：中文")
                            settingInfo.saveSettingParam("system_language","chinese")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "英文"
                        checked: language === "english"
                        onClicked: {
                            language = "english"
                            console.log("语言设置：英文")
                            settingInfo.saveSettingParam("system_language","english")
                        }
                    }
                }
            }

            SettingSection {
                title: "数据采样时间："

                content: GridLayout {
                    columnSpacing: 100
                    rowSpacing: 24
                    height: implicitHeight
                    columns: 4
                    flow: GridLayout.LeftToRight
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "10秒"
                        checked: dataSamplingPeriod === "10s"
                        onClicked: {
                            dataSamplingPeriod = "10s"
                            console.log("数据采样时间10S")
                            settingInfo.saveSettingParam("system_dataSamplingPeriod","10s")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "20秒"
                        checked: dataSamplingPeriod === "20s"
                        onClicked: {
                            dataSamplingPeriod = "20s"
                            console.log("数据采样时间20S")
                            settingInfo.saveSettingParam("system_dataSamplingPeriod","20s")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "30秒"
                        checked: dataSamplingPeriod === "30s"
                        onClicked: {
                            dataSamplingPeriod = "30s"
                            console.log("数据采样时间30S")
                            settingInfo.saveSettingParam("system_dataSamplingPeriod","30s")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "1分钟"
                        checked: dataSamplingPeriod === "1min"
                        onClicked: {
                            dataSamplingPeriod = "1min"
                            console.log("数据采样时间1min")
                            settingInfo.saveSettingParam("system_dataSamplingPeriod","1min")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "2分钟"
                        checked: dataSamplingPeriod === "2min"
                        onClicked: {
                            dataSamplingPeriod = "2min"
                            console.log("数据采样时间2min")
                            settingInfo.saveSettingParam("system_dataSamplingPeriod","2min")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "5分钟"
                        checked: dataSamplingPeriod === "5min"
                        onClicked: {
                            dataSamplingPeriod = "5min"
                            console.log("数据采样时间5min")
                            settingInfo.saveSettingParam("system_dataSamplingPeriod","5min")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "10分钟"
                        checked: dataSamplingPeriod === "10min"
                        onClicked: {
                            dataSamplingPeriod = "10min"
                            console.log("数据采样时间10min")
                            settingInfo.saveSettingParam("system_dataSamplingPeriod","10min")
                        }
                    }
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "30分钟"
                        checked: dataSamplingPeriod === "30min"
                        onClicked: {
                            dataSamplingPeriod = "30min"
                            console.log("数据采样时间30min")
                            settingInfo.saveSettingParam("system_dataSamplingPeriod","30min")
                        }
                    }
                }
            }
            // 重量单位设置
            SettingSection {
                title: "重量单位设置："
                content: RowLayout {
                    spacing: 100

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "g"
                        checked: weightUnit === "g"
                        onClicked: {
                            weightUnit = "g"
                            console.log("重量单位设置：g")
                            settingInfo.saveSettingParam("system_weightUnit","g")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "kg"
                        checked: weightUnit === "kg"
                        onClicked: {
                            weightUnit = "kg"
                            console.log("重量单位设置：kg")
                            settingInfo.saveSettingParam("system_weightUnit","kg")
                        }
                    }
                }
            }
            // 重量小数位数设置
            SettingSection {
                title: "重量小数位数设置："
                content: RowLayout {
                    spacing: 100

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "1位"
                        checked: decimalPlaces === "1"
                        onClicked: {
                            decimalPlaces = "1"
                            console.log("重量小数位数设置：1")
                            settingInfo.saveSettingParam("system_decimalPlaces","1")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "2位"
                        checked: decimalPlaces === "2"
                        onClicked: {
                            decimalPlaces = "2"
                            console.log("重量小数位数设置：2")
                            settingInfo.saveSettingParam("system_decimalPlaces","2")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "3位"
                        checked: decimalPlaces === "3"
                        onClicked: {
                            decimalPlaces = "3"
                            console.log("重量小数位数设置：3")
                            settingInfo.saveSettingParam("system_decimalPlaces","3")
                        }
                    }
                }
            }

            // 温度单位设置
            SettingSection {
                title: "温度单位设置："
                content: RowLayout {
                    spacing: 100

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "°C"
                        checked: temperatureUnit === "celsius"
                        onClicked: {
                            temperatureUnit = "celsius"
                            console.log("温度单位设置：°C")
                            settingInfo.saveSettingParam("system_temperatureUnit","celsius")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "°F"
                        checked: temperatureUnit === "fahrenheit"
                        onClicked: {
                            temperatureUnit = "fahrenheit"
                            console.log("温度单位设置：°F")
                            settingInfo.saveSettingParam("system_temperatureUnit","fahrenheit")
                        }
                    }
                }
            }

            // 日期格式设置
            SettingSection {
                title: "日期格式设置："
                content: RowLayout {
                    spacing: 100

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "YYYY/MM/DD"
                        checked: dateFormat === "yyyy_mm_dd"
                        onClicked: {
                            dateFormat = "yyyy_mm_dd"
                            console.log("日期格式设置：YYYY/MM/DD")
                            settingInfo.saveSettingParam("system_dateFormat","yyyy_mm_dd")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "MM/DD/YYYY"
                        checked: dateFormat === "mm_dd_yyyy"
                        onClicked: {
                            dateFormat = "mm_dd_yyyy"
                            console.log("日期格式设置：MM/DD/YYYY")
                            settingInfo.saveSettingParam("system_dateFormat","mm_dd_yyyy")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "DD/MM/YYYY"
                        checked: dateFormat === "dd_mm_yyyy"
                        onClicked: {
                            dateFormat = "dd_mm_yyyy"
                            console.log("日期格式设置：DD/MM/YYYY")
                            settingInfo.saveSettingParam("system_dateFormat","dd_mm_yyyy")
                        }
                    }
                }
            }

            // 时间格式设置
            SettingSection {
                title: "时间格式设置："
                content: RowLayout {
                    spacing: 100

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "hh:mm:ss"
                        checked: timeFormat === "hh_mm_ss"
                        onClicked: {
                            timeFormat = "hh_mm_ss"
                            console.log("时间格式设置：hh:mm:ss")
                            settingInfo.saveSettingParam("system_timeFormat","hh_mm_ss")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "hh:mm"
                        checked: timeFormat === "hh_mm"
                        onClicked: {
                            timeFormat = "hh_mm"
                            console.log("时间格式设置：hh:mm")
                            settingInfo.saveSettingParam("system_timeFormat","hh_mm")
                        }
                    }
                }
            }

            // 时钟设置
            SettingSection {
                title: "时钟设置："
                showGoToSettingsButton: true
                onGoToSettingsClicked: {
                    console.log("点击时钟设置的去设置按钮")
                    swipeSettingManagementView.currentIndex = 1;
                    // if (typeof stackView !== 'undefined') {
                    //     stackView.push(Qt.resolvedUrl("qrc:/pages/SystemTimePage.qml"))
                    // }
                }
                content: RowLayout {
                    spacing: 100

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "本地时间"
                        checked: clockType === "local"
                        onClicked: {
                            clockType = "local"
                            console.log("时钟设置：本地时间")
                            settingInfo.saveSettingParam("system_clockType","local")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "网络时间"
                        checked: clockType === "network"
                        onClicked: {
                            clockType = "network"
                            console.log("时钟设置：网络时间")
                            settingInfo.saveSettingParam("system_clockType","network")
                        }
                    }
                }
            }

            // 电子签名设置
            SettingSection {
                title: "电子签名设置："
                content: RowLayout {
                    spacing: 100

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "1个电子签名"
                        checked: signatureType === "one"
                        onClicked: {
                            signatureType = "one"
                            console.log("电子签名设置：1个电子签名")
                            settingInfo.saveSettingParam("system_signatureType","one")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "2个电子签名"
                        checked: signatureType === "two"
                        onClicked: {
                            signatureType = "two"
                            console.log("电子签名设置：2个电子签名")
                            settingInfo.saveSettingParam("system_signatureType","two")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "无"
                        checked: signatureType === "none"
                        onClicked: {
                            signatureType = "none"
                            console.log("电子签名设置：无")
                            settingInfo.saveSettingParam("system_signatureType","none")
                        }
                    }
                }
            }

            // 网络通讯设置
            SettingSection {
                title: "网络通讯："
                showGoToSettingsButton: true
                onGoToSettingsClicked: {
                    console.log("点击网络设置的去设置按钮")
                    // 这里可以添加跳转到网络设置页面的逻辑
                }
                content: RowLayout {
                    spacing: 100

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "有线网络"
                        checked: networkType === "wired"
                        onClicked: {
                            networkType = "wired"
                            console.log("网络通讯设置：有线网络")
                            settingInfo.saveSettingParam("system_networkType","wired")
                        }
                    }

                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "无线网络"
                        checked: networkType === "wireless"
                        onClicked: {
                            networkType = "wireless"
                            console.log("网络通讯设置：无线网络")
                            settingInfo.saveSettingParam("system_networkType","wireless")
                        }
                    }
                }
            }
        }

        // 登录设置内容
        Column {
            id: loginCol
            width: scrollFlick.width - 40
            spacing: 24
            anchors.horizontalCenter: parent.horizontalCenter
            visible: currentTab === "login"

            // 密码复杂程度设置
            SettingSection {
                title: "密码复杂程度设置："
                content: Column {
                    spacing: 16

                    // 胶囊分段控件：简易/复杂
                    Item {
                        width: 140
                        height: 40

                        // 外层胶囊边框与背景
                        Rectangle {
                            id: capsule
                            anchors.fill: parent
                            radius: 5
                            color: "white"
                            border.width: 2
                            border.color: theme.focusColor
                            clip: true
                        }

                        // 选中填充半块（蓝色）
                        Rectangle {
                            id: selectionFill
                            anchors.top: capsule.top
                            anchors.bottom: capsule.bottom
                            radius: 5
                            width: capsule.width / 2
                            x: passwordComplexity === "simple" ? 0 : capsule.width / 2
                            color: theme.focusColor
                        }

                        // 左侧文字：简易
                        Text {
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.left: parent.left
                            anchors.leftMargin: 18
                            text: "简易"
                            font.pixelSize: 18
                            font.bold: true
                            color: passwordComplexity === "simple" ? "white" : "#7A8CA5"
                        }

                        // 右侧文字：复杂
                        Text {
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.right: parent.right
                            anchors.rightMargin: 18
                            text: "复杂"
                            font.pixelSize: 18
                            font.bold: true
                            color: passwordComplexity === "complex" ? "white" : "#7A8CA5"
                        }

                        MouseArea {
                            anchors.fill: parent
                            cursorShape: Qt.PointingHandCursor
                            onClicked: function(mouse) {
                                passwordComplexity = mouse.x < parent.width / 2 ? "simple" : "complex";
                                console.log("登录设置-密码复杂度：" + (passwordComplexity === "simple" ? "简易" : "复杂"))
                                settingInfo.saveSettingParam("login_passwordComplexity",passwordComplexity === "simple" ?"simple":"complex")
                            }
                        }
                    }

                    // 密码长度选项
                    RowLayout {
                        spacing: 100

                        SettingCheckBox {
                            Layout.preferredWidth: 260
                            text: "6位"
                            checked: passwordLength === 6
                            onClicked: {
                                passwordLength = 6; console.log("登录设置-密码长度：6位")
                                settingInfo.saveSettingParam("login_passwordLength", passwordLength+"")
                            }
                        }
                        SettingCheckBox {
                            Layout.preferredWidth: 260
                            text: "8位"
                            checked: passwordLength === 8
                            onClicked: {
                                passwordLength = 8; console.log("登录设置-密码长度：8位")
                                settingInfo.saveSettingParam("login_passwordLength", passwordLength+"")
                            }
                        }
                        SettingCheckBox {
                            Layout.preferredWidth: 260
                            text: "10位"
                            checked: passwordLength === 10
                            onClicked: {
                                passwordLength = 10; console.log("登录设置-密码长度：10位")
                                settingInfo.saveSettingParam("login_passwordLength", passwordLength+"")
                            }
                        }
                        SettingCheckBox {
                            Layout.preferredWidth: 260
                            text: "12位"
                            checked: passwordLength === 12
                            onClicked: {
                                passwordLength = 12; console.log("登录设置-密码长度：12位")
                                settingInfo.saveSettingParam("login_passwordLength", passwordLength+"")
                            }
                        }
                    }
                }
            }

            // 密码错误锁屏次数
            SettingSection {
                title: "密码错误锁屏次数："
                content: RowLayout {
                    spacing: 100
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "3"
                        checked: passwordLockAttempts === "3"
                        onClicked: {
                            passwordLockAttempts = "3"; console.log("登录设置-错误次数：3")
                            settingInfo.saveSettingParam("login_passwordLockAttempts",passwordLockAttempts)
                        }
                    }
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "5"
                        checked: passwordLockAttempts === "5"
                        onClicked: {
                            passwordLockAttempts = "5"; console.log("登录设置-错误次数：5")
                            settingInfo.saveSettingParam("login_passwordLockAttempts",passwordLockAttempts)
                        }
                    }
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "10"
                        checked: passwordLockAttempts === "10"
                        onClicked: {
                            passwordLockAttempts = "10"; console.log("登录设置-错误次数：10")
                            settingInfo.saveSettingParam("login_passwordLockAttempts",passwordLockAttempts)
                        }
                    }
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "无"
                        checked: passwordLockAttempts === "none"
                        onClicked: {
                            passwordLockAttempts = "none"; console.log("登录设置-错误次数：无")
                            settingInfo.saveSettingParam("login_passwordLockAttempts",passwordLockAttempts)
                        }
                    }
                }
            }

            // 锁屏锁定时间
            SettingSection {
                title: "锁屏锁定时间："
                content: GridLayout {
                    columns: 4
                    columnSpacing: 100
                    rowSpacing: 24
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "3分钟"
                        checked: lockDuration === "3min"
                        onClicked: {
                            lockDuration = "3min"; console.log("登录设置-锁定时间：3分钟")
                            settingInfo.saveSettingParam("login_lockDuration",lockDuration)
                        }
                    }
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "5分钟"
                        checked: lockDuration === "5min"
                        onClicked: {
                            lockDuration = "5min"; console.log("登录设置-锁定时间：5分钟")
                            settingInfo.saveSettingParam("login_lockDuration",lockDuration)
                        }
                    }
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "10分钟"
                        checked: lockDuration === "10min"
                        onClicked: {
                            lockDuration = "10min"; console.log("登录设置-锁定时间：10分钟")
                            settingInfo.saveSettingParam("login_lockDuration",lockDuration)
                        }
                    }
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "30分钟"
                        checked: lockDuration === "30min"
                        onClicked: {
                            lockDuration = "30min"; console.log("登录设置-锁定时间：30分钟")
                            settingInfo.saveSettingParam("login_lockDuration",lockDuration)
                        }
                    }
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "24小时"
                        checked: lockDuration === "24h"
                        onClicked: {
                            lockDuration = "24h"; console.log("登录设置-锁定时间：24小时")
                            settingInfo.saveSettingParam("login_lockDuration",lockDuration)
                        }
                    }
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "无"
                        checked: lockDuration === "none"
                        onClicked: {
                            lockDuration = "none"; console.log("登录设置-锁定时间：无")
                            settingInfo.saveSettingParam("login_lockDuration",lockDuration)
                        }
                    }
                }
            }

            // 自动登出等待时间
            SettingSection {
                title: "自动登出等待时间："
                content: GridLayout {
                    columns: 4
                    columnSpacing: 100
                    rowSpacing: 24
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "5分钟"
                        checked: autoLogoutWait === "5min"
                        onClicked: {
                            autoLogoutWait = "5min"; console.log("登录设置-自动登出：5分钟")
                            settingInfo.saveSettingParam("login_autoLogoutWait", autoLogoutWait)
                        }
                    }
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "10分钟"
                        checked: autoLogoutWait === "10min"
                        onClicked: {
                            autoLogoutWait = "10min"; console.log("登录设置-自动登出：10分钟")
                            settingInfo.saveSettingParam("login_autoLogoutWait", autoLogoutWait)
                        }
                    }
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "30分钟"
                        checked: autoLogoutWait === "30min"
                        onClicked: {
                            autoLogoutWait = "30min"; console.log("登录设置-自动登出：30分钟")
                            settingInfo.saveSettingParam("login_autoLogoutWait", autoLogoutWait)
                        }
                    }
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "60分钟"
                        checked: autoLogoutWait === "60min"
                        onClicked: {
                            autoLogoutWait = "60min"; console.log("登录设置-自动登出：60分钟")
                            settingInfo.saveSettingParam("login_autoLogoutWait", autoLogoutWait)
                        }
                    }
                    SettingCheckBox {
                        Layout.preferredWidth: 260
                        text: "无"
                        checked: autoLogoutWait === "none"
                        onClicked: {
                            autoLogoutWait = "none"; console.log("登录设置-自动登出：无")
                            settingInfo.saveSettingParam("login_autoLogoutWait", autoLogoutWait)
                        }
                    }
                }
            }
        }


        // 设置区域组件
        component SettingSection: Item {
            property string title: ""
            default property alias content: contentItem.data
            property bool showGoToSettingsButton: false
            signal goToSettingsClicked()

            width: parent.width
            height: cardRect.height

            Rectangle {
                id: cardRect
                width: parent.width
                height: titleText.height + contentItem.childrenRect.height + 80
                radius: 15
                color: "#FFFFFF"

                layer.enabled: false
                layer.effect: MultiEffect {
                    shadowEnabled: true
                    shadowColor: theme.shadowColor
                    shadowBlur: theme.shadowBlur
                    shadowHorizontalOffset: theme.shadowXOffset
                    shadowVerticalOffset: theme.shadowYOffset
                }

                Text {
                    id: titleText
                    anchors.top: parent.top
                    anchors.left: parent.left
                    anchors.topMargin: 30
                    anchors.leftMargin: 60
                    text: title
                    font.pixelSize: 24
                    color: theme.secondaryColor
                    font.bold: true
                }

                // "去设置>" 按钮
                Rectangle {
                    id: goToSettingsButton
                    visible: showGoToSettingsButton
                    anchors.top: parent.top
                    anchors.right: parent.right
                    anchors.topMargin: 25
                    anchors.rightMargin: 30
                    width: 120
                    height: 40
                    radius: 0
                    color: "#1090CE"
                    scale: pressed ? 0.95 : 1
                    property bool pressed: false

                    Text {
                        anchors.centerIn: parent
                        text: "去设置>"
                        font.pixelSize: 18
                        color: "white"
                        font.bold: true
                    }

                    MouseArea {
                        anchors.fill: parent
                        cursorShape: Qt.PointingHandCursor
                        onPressed: goToSettingsButton.pressed = true
                        onReleased: goToSettingsButton.pressed = false
                        onClicked:{
                            goToSettingsClicked()
                        }
                    }
                }

                Item {
                    id: contentItem
                    anchors.top: titleText.bottom
                    anchors.left: parent.left
                    anchors.right: parent.right
                    anchors.topMargin: 20
                    anchors.leftMargin: 60
                    anchors.rightMargin: 20
                    height: childrenRect.height
                }
            }
        }

        // 复选框
        component SettingCheckBox: Item {
            property string text: ""
            property bool checked: false
            signal clicked()

            width: checkBox.width + label.width + 10
            height: 40

            Rectangle {
                id: checkBox
                width: 24
                height: 24
                anchors.verticalCenter: parent.verticalCenter
                radius: 4
                border.width: 2
                border.color: checked ? theme.focusColor : "#CCCCCC"
                color: checked ? theme.focusColor : "transparent"

                Text {
                    anchors.centerIn: parent
                    text: "\uf00c"
                    color: "white"
                    font.pixelSize: 16
                    font.family: iconFont.name
                    visible: checked
                }
            }

            Text {
                id: label
                anchors.left: checkBox.right
                anchors.leftMargin: 10
                anchors.verticalCenter: parent.verticalCenter
                text: parent.text
                font.pixelSize: 20
                color: theme.secondaryColor
            }

            MouseArea {
                anchors.fill: parent
                cursorShape: Qt.PointingHandCursor
                onClicked: parent.clicked()
            }
        }
    }
}
